Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of BACKUP.SH</TITLE>
</HEAD><BODY>
<H1>BACKUP.SH</H1>
Section: User Commands  (1)<BR>Updated: LOCAL<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>

<P>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>

backup.sh - manage import and export data from modules
<P>
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>

backup.sh 
<I>[options]</I>

<B>-l</B>

<P>
backup.sh
<I>[options] &lt;module&gt;</I>

<B>import|export </B>

<I>&lt;destination&gt;</I>

<P>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>

<B>backup.sh</B>

can manage saved data of  
a set of modules with exporting (save) or importing (restore) the data.
<P>
With this script you can manage easily an application using multiples modules.
<P>
<A NAME="lbAE">&nbsp;</A>
<H2>OPTIONS</H2>

<DL COMPACT>
<DT>-D <DD>
indicates to erase current data before importation.
<P>
<DT>-M &lt;directory&gt;<DD>
indicates the path of the modules files (see MODULES).
default : backup-modules
<P>
<DT>-E &lt;file&gt;<DD>
indicates the path of the environment file (see MODULES).
default: 
<I>none</I>

<P>
<DT>-l<DD>
show the list of modules.
<P>
<DT>-A nosys<DD>
action on all modules without
<B>sys </B>

prefix.
Use it instead &lt;module&gt;.
<P>
<DT>-A allsys<DD>
action on all modules.
Use it instead &lt;module&gt;.
<P>
<DT>-v<DD>
show this 
<B>backup.sh </B>

script's version.
<P>
<DT>-?<DD>
show the help message.
<P>
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>COMMANDS</H2>

<DL COMPACT>
<DT>export &lt;destination&gt;<DD>
export the data of a module to a save under the destination directory.
<P>
<DT>import<DD>
import the data of a module from a previous save under the destination directory.
<P>
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>MODULES</H2>

A module is a file describing how to export and import data of a component.
It's a script file with particular format (see below).
This file contains shell functions and description. 
An environment file can be used too for storing parameters or global functions.
<P>
<A NAME="lbAH">&nbsp;</A>
<H3>Environment file</H3>

It's an optional script launched on current shell (with 
<B>. (dot) </B>

command). This file must be indicated with the 
<B>-E </B>

option.
<P>
<A NAME="lbAI">&nbsp;</A>
<H3>Filename</H3>

This module's file must be in a directory (by default 
<I>backup-modules</I>

) with one of this format :
<I>&lt;number&gt;_&lt;name&gt;</I>

or
<I>&lt;number&gt;_sys_&lt;name&gt;</I>

were 
<DL COMPACT>
<DT>&lt;number&gt;<DD>
is a number. It indicates the order to export this module when 
<B>-A </B>

option is used. When importing, the order is reversed.
<P>
<DT>&lt;name&gt;<DD>
is the name you want.
<DT>sys<DD>
is used for indicated a system module.
<P>
</DL>
<A NAME="lbAJ">&nbsp;</A>
<H3>System modules</H3>

A system module represents a component used globally on the system. Like 
<I>ldap server</I>

or
<I>dns server </I>

that is when stopping this component has an impact on the machine and on the other applications.
<P>
<A NAME="lbAK">&nbsp;</A>
<H3>Format of the file</H3>

The file must contain description of the module (comment with NNNA) and 2 shell functions:
<DL COMPACT>
<DT>fn_export<DD>
<DT>fn_import.<DD>
<P>
<P>
<P>
Below, a template for the file:
<P>
<BR>&nbsp;#!/bin/sh
<P>
<BR>&nbsp;#&nbsp;#################################################&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;description&nbsp;describe&nbsp;here&nbsp;the&nbsp;component&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;you&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version&nbsp;of&nbsp;the&nbsp;script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;#################################################&nbsp;#
<P>
<BR>&nbsp;fn_import()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;if&nbsp;[&nbsp;&quot;$1&quot;&nbsp;=&nbsp;'-D'&nbsp;];&nbsp;then
<BR>&nbsp;&nbsp;&nbsp;#delete&nbsp;all&nbsp;data&nbsp;(erase)
<BR>&nbsp;&nbsp;&nbsp;shift&nbsp;1
<BR>&nbsp;&nbsp;&nbsp;foobar
<BR>&nbsp;&nbsp;fi
<BR>&nbsp;&nbsp;#import&nbsp;the&nbsp;data&nbsp;from&nbsp;$1
<BR>&nbsp;&nbsp;foo&nbsp;$1
<BR>&nbsp;&nbsp;return&nbsp;0&nbsp;#ok
<BR>&nbsp;}
<P>
<BR>&nbsp;fn_export()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;&nbsp;#export&nbsp;the&nbsp;data&nbsp;to&nbsp;$1
<BR>&nbsp;&nbsp;&nbsp;faabar&nbsp;$1
<BR>&nbsp;&nbsp;&nbsp;return&nbsp;0&nbsp;#ok
<BR>&nbsp;}
<P>
<P>
</DL>
<A NAME="lbAL">&nbsp;</A>
<H2>EXAMPLE</H2>

For instance if your application is composed by a website and database, you can create two module : 
<DL COMPACT>
<DT>one for the website<DD>
<DT>another for the database<DD>
<P>
<P>
<P>
</DL>
<A NAME="lbAM">&nbsp;</A>
<H3>Website</H3>

The website is hosted in a virtualhost on a shared Apache server. 
So, the Apache is a system module.
We create the file 
<B>backup-modules/20_sys_apache.</B>

Below the content
<BR>&nbsp;#!/bin/sh
<BR>&nbsp;
<BR>&nbsp;#&nbsp;#################################################&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;description&nbsp;apache&nbsp;web&nbsp;server&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Example'&nbsp;author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version&nbsp;1.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;#################################################&nbsp;#&nbsp;
<P>
<BR>&nbsp;fn_export()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;tar&nbsp;czvf&nbsp;$1/apache.tgz&nbsp;/var/nnnadminexample/mywebsite/htdocs
<BR>&nbsp;&nbsp;return&nbsp;$?
<BR>&nbsp;}
<BR>&nbsp;
<BR>&nbsp;fn_import()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;if&nbsp;[&nbsp;&quot;$1&quot;&nbsp;=&nbsp;'-D'&nbsp;];&nbsp;then
<BR>&nbsp;&nbsp;&nbsp;#delete&nbsp;before&nbsp;remove&nbsp;not&nbsp;supported
<BR>&nbsp;&nbsp;&nbsp;shift&nbsp;1
<BR>&nbsp;&nbsp;fi
<BR>&nbsp;&nbsp;cd&nbsp;/
<BR>&nbsp;&nbsp;tar&nbsp;xzf&nbsp;$1/apache.tgz&nbsp;
<BR>&nbsp;&nbsp;cd&nbsp;-&gt;/dev/null
<BR>&nbsp;&nbsp;return&nbsp;$?
<BR>&nbsp;}
<P>
<A NAME="lbAN">&nbsp;</A>
<H3>Database</H3>

The database instance is launched on standalone but must be launch before Apache.
We create the file
<B>backup-modules/10_database.</B>

Below the content
<BR>&nbsp;#!/bin/sh
<BR>&nbsp;
<BR>&nbsp;#&nbsp;#################################################&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;description&nbsp;database&nbsp;of&nbsp;the&nbsp;website&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Example'&nbsp;author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;NNNA&nbsp;version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version&nbsp;1.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
<BR>&nbsp;#&nbsp;#################################################&nbsp;#&nbsp;
<P>
<BR>&nbsp;PG_DIR=/usr/lib/postgresql/9.1/bin
<BR>&nbsp;PGDATA=/var/nnnadminexample/mydatabase
<BR>&nbsp;
<BR>&nbsp;fn_export()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;su&nbsp;-&nbsp;postgres&nbsp;-c&nbsp;&quot;PGDATA=$PGDATA;$PG_DIR/pg_dump&nbsp;-Ft&nbsp;-f&nbsp;$1/base.tar&quot;
<BR>&nbsp;&nbsp;return&nbsp;$?
<BR>&nbsp;}&nbsp;
<BR>&nbsp;
<BR>&nbsp;fn_import()
<BR>&nbsp;{
<BR>&nbsp;&nbsp;unset&nbsp;opt
<BR>&nbsp;&nbsp;if&nbsp;[&nbsp;&quot;$1&quot;&nbsp;=&nbsp;'-D'&nbsp;];&nbsp;then
<BR>&nbsp;&nbsp;&nbsp;opt='-c'
<BR>&nbsp;&nbsp;fi
<BR>&nbsp;&nbsp;su&nbsp;-&nbsp;postgres&nbsp;-c&nbsp;&quot;PGDATA=$PGDATA;$PG_DIR/pg_restore&nbsp;$opt&nbsp;-Ft&nbsp;&lt;$1/base.tar&quot;
<BR>&nbsp;&nbsp;return&nbsp;$?
<BR>&nbsp;}
<P>
<A NAME="lbAO">&nbsp;</A>
<H3>Exporting database only (to /backup directory)</H3>

backup.sh database export /backup
<P>
<A NAME="lbAP">&nbsp;</A>
<H3>Exporting all</H3>

backup.sh -A allsys export /backup
<P>
<A NAME="lbAQ">&nbsp;</A>
<H3>Importing to apache from /backup directory</H3>

backup.sh apache import /backup
<P>
<A NAME="lbAR">&nbsp;</A>
<H2>AUTHOR</H2>

3Zen
<P>
<A NAME="lbAS">&nbsp;</A>
<H2>SEE ALSO</H2>

<B><A HREF="/cgi-bin/man/man2html?1+admin.sh">admin.sh</A>(1),</B>

<B><A HREF="/cgi-bin/man/man2html?1+check.sh">check.sh</A>(1),</B>

<B><A HREF="/cgi-bin/man/man2html?1+launch.sh">launch.sh</A>(1)</B>

<P>

<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT><A HREF="#lbAE">OPTIONS</A><DD>
<DT><A HREF="#lbAF">COMMANDS</A><DD>
<DT><A HREF="#lbAG">MODULES</A><DD>
<DL>
<DT><A HREF="#lbAH">Environment file</A><DD>
<DT><A HREF="#lbAI">Filename</A><DD>
<DT><A HREF="#lbAJ">System modules</A><DD>
<DT><A HREF="#lbAK">Format of the file</A><DD>
</DL>
<DT><A HREF="#lbAL">EXAMPLE</A><DD>
<DL>
<DT><A HREF="#lbAM">Website</A><DD>
<DT><A HREF="#lbAN">Database</A><DD>
<DT><A HREF="#lbAO">Exporting database only (to /backup directory)</A><DD>
<DT><A HREF="#lbAP">Exporting all</A><DD>
<DT><A HREF="#lbAQ">Importing to apache from /backup directory</A><DD>
</DL>
<DT><A HREF="#lbAR">AUTHOR</A><DD>
<DT><A HREF="#lbAS">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 22:11:13 GMT, March 25, 2013
</BODY>
</HTML>
